package com.lc.advertising.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.bar.TitleBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.advertising.R;
import com.lc.advertising.app.AppActivity;
import com.lc.advertising.http.request.CardListApi;
import com.lc.advertising.http.response.CardListBean;
import com.lc.advertising.other.IntentKey;
import com.lc.advertising.util.SPUtil;

import org.jetbrains.annotations.NotNull;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BankCartActivity extends AppActivity {
    @BindView(R.id.title_top)
    TitleBar titleTop;
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    private BaseQuickAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_bankcart;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        recyclerview.setLayoutManager(new LinearLayoutManager(this));
        adapter = new BaseQuickAdapter<CardListBean.BankBean, BaseViewHolder>(R.layout.item_bank) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, CardListBean.BankBean dataBean) {
                holder.setText(R.id.tv_name,dataBean.getCardname());
                holder.setText(R.id.tv_cart_num,dataBean.getCardnum());
                holder.getView(R.id.tv_edit).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        startActivity(new Intent(BankCartActivity.this,AddBankCartActivity.class).putExtra("card_people",dataBean.getCard_people()).putExtra("mobile",dataBean.getMobile()).putExtra("ycardnum",dataBean.getYcardnum()).putExtra("type","修改").putExtra("id",dataBean.getId()+""));
                    }
                });

            }
        };
        recyclerview.setAdapter(adapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        BankCart();
    }

    private void BankCart() {
        EasyHttp.post(this)
                .api(new CardListApi().setUid(SPUtil.get(this,IntentKey.UID,"")))
                .request(new HttpCallback<CardListBean>(this) {



                    @Override
                    public void onSucceed(CardListBean data) {

                        if (data.getCode()==200){
                            adapter.setNewData(data.getBank());

                        }


                    }

                });

    }

    @OnClick(R.id.add_tianjia)
    public void onClick() {
        startActivity(new Intent(BankCartActivity.this,AddBankCartActivity.class).putExtra("type","添加"));
    }
}
